import argparse
from gcj2wgs2 import gcj2wgs_exact


def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('in_file', help='path to the text file')
    parser.add_argument('-o', '--output', default="output.txt", help='output file name')
    return parser.parse_args()


def main():
    args = parse_args()
    with open(args.output, 'w') as out:
        with open(args.in_file) as f:
            for line in f:
                line = line.split(',')
                if line[-2] == 'Null':
                    continue
                la = float(line[-1])
                lo = float(line[-2])
                wgs_la, wgs_lo = gcj2wgs_exact(la, lo)
                line[-1] = str(wgs_la)
                line[-2] = str(wgs_lo)
                line.append('WGS_84')
                out.write(' '.join(line) + '\n')


if __name__ == '__main__':
    main()
